﻿using System;
using System.Web.Mvc;
using WikiPlex.Formatting;


namespace MvcCms.Service.Code.Wiki
{
    public class AnyStyleRenderer : IRenderer
    {
        private const string AnyStyleFormat = "<span style=\"{0}\">{1}</span>";

        public AnyStyleRenderer()
        {

        }

        public string Id
        {
            get { return "Wiki Any Style Renderer"; }
        }

        public bool CanExpand(string scopeName)
        {
            return scopeName == WikiScopeName.WikiAnyStyle;
        }

        public string Expand(string scopeName, string input, Func<string, string> htmlEncode, Func<string, string> attributeEncode)
        {
            var array = input.Split('|');
            if (array.Length == 2)
            {
                return string.Format(AnyStyleFormat, htmlEncode(array[0]), htmlEncode(array[1]));
            }
            else
            {
                return input;
            }
        }
    }
}